<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('直发出库新增及修改')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <th:block th:include="include :: business_btn" />
	        <th:block th:include="include :: business_tpl('top')" />
    	</div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	    <th:block th:include="include :: pageFooter" /> 
        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<!-- 物流信息 -->
<script id="change1" type="text/template">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="width:calc(100%-30px)">
		<div class="layui-form-item margin_t0">
			<div th:class="'layui-inline margin_r0 '+${field.fieldFrontTopSize eq 1 ?'layui-col-sm4':(field.fieldFrontTopSize eq 2 ?'layui-col-sm8':'layui-col-sm12')}" th:each="field : ${fieldsList}" th:if="${field.fieldExceptEdit}">
               	<label class="layui-form-label">
                	<font class="f_red" th:if="${#bools.isTrue(field?.fieldFrontRequired)}">*</font>[[${field.fieldName}]]：
              	</label>
               	<div class="layui-input-block">
                    <input th:if="${field.fieldFrontType} eq 't_text'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''"  class="layui-input">
                    <input th:if="${field.fieldFrontType} eq 't_decimal'" type="number" lay-verify="number" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''" class="layui-input">
                    <input th:if="${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:class="${field.fields} eq 'createTime'?'layui-input t_date canntEdit':'layui-input t_date'" readonly>
                    	<i th:if="(${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime') and ${field.fields} neq 'createTime'" class="dhicon dh-calendar icon_date_business"></i>
			    	<input th:if="${field.fieldFrontType} eq 't_checkbox'" type="checkbox" th:checked="${field?.fieldContent == false or field?.fieldContent == null}" value="0" th:name="${field?.fields}" th:id="${field?.fields}" lay-skin="switch" th:lay-text="${field?.fields == 'bDeleted'} ? '启用|禁用' : '是|否'" th:disabled="${gridColumns.readOnly}">
				  	<input th:if="${field.fieldFrontType} eq 't_buttontext'" type="text" th:class="${field.fieldFrontEdit}?'layui-input buttontext':'layui-input canntEdit'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/>
				  		<i th:if="${field.fieldFrontType} eq 't_buttontext' and ${field.fieldFrontEdit}" class="layui-icon layui-icon-more getMore" th:onclick="getMore([[${field?.fields}]],null,[[${field?.fieldName}]],[[${field?.fieldSearchType}]]);" th:getType="${field?.fields}"></i>
					<textarea th:if="${field.fieldFrontType} eq 't_textarea'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" th:class="${field?.fieldFrontEdit}?'layui-textarea':'layui-textarea canntEdit'" th:readonly="${field?.fieldFrontEdit}?'false':'true'">[[${field.fieldContent}]]</textarea>
					<select th:if="${field.fieldFrontType} eq 't_dropdown'" type="text" th:id="${field?.fields}" th:name="${field?.fields}" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}" lay-filter="select_top" th:data-fieldMatched="${field?.fieldMatched}" th:data-fieldFrontSave="${field?.fieldFrontSave}" th:data-fieldFrontShow="${field?.fieldFrontShow}">
						<option></option>
						<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}" th:data-vremark="${dict.vremark}"></option>
					</select>
					<input th:if="${field.fieldFrontType} eq 't_dropdownedit'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" class="layui-input" style="position:absolute;overflow:hidden;z-index:2;width: calc(100% - 30px);" lay-verify="required" onkeyup="inputSearch()" onblur="refreshSelect()" autocomplete="off">
	               	<select th:if="${field.fieldFrontType} eq 't_dropdownedit'" th:id="${field?.fields}+'_select1'" th:lay-filter="${field?.fields}+'_select'" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}">
						<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}"></option>
					</select>
					<input th:if="${field.fieldFrontType} eq 't_file'" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/><i th:if="${field.fieldFrontType} eq 't_file'" class="layui-icon layui-icon-upload getUpload" th:onclick="getUpload([[${field?.fields}]]);" th:getType="${field?.fields}"></i>
				</div>
            </div>
        </div>
	</div>
</script>
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
console.log(k_fields);
var $,layer,form,table,laydate,element;//定义layui模块
eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/business/outdirect/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		initTable();//初始化表格
	});
	//头部event事件
	table.on('toolbar(ftable)', function(obj){
		var checkStatus = table.checkStatus('dhtable');
	    switch(obj.event){
	    	case 'addBtn':
	    		if(listData.length > 0){
	    			if(listData[listData.length - 1]['iid']){
	    				gridColumns.gridNewLine.iid = Number(listData[listData.length - 1]['iid']) + 1;//行号自增1
	    			}else{
	    				gridColumns.gridNewLine.iid = 1;
	    			}
	    		}else{
	    			gridColumns.gridNewLine.iid = 1;
	    		}
	    		listData.push(gridColumns.gridNewLine);
	        	table.reload('dhtable', {data : listData});
	      		form.render();
	    	break;
	    	case 'deleteBatch':
	    		tableDeleteBatch('dhtable', listData, checkStatus);
	    	break;
	    	case 'fieldSet':
	    		filedSet(moduleTable+'_EditPage202109');
         	break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	    	case 'importBtn':
	    		$.tablelist.importExcel('dhtable',importFields, table.cache.dhtable, moduleTable, decimalObj);
         	break;
	    	case 'change':
	    		layer.open({
            		type: 1,
            		area: [($(window).width() - 400)+'px', ($(window).height() - 200)+'px'],
            		fix: false,//不固定
            		offset: '10%',//距离顶部
            		maxmin: true,//最大最小化
            		shade: 0.3,//遮罩
            		title: '物流信息',
            		content: $('#change1').html(),
            		btn: ['保存', '取消'],
            		shadeClose: true,// 弹层外区域关闭
            		success: function(layero, index){
            			$.each(k_fields,function(i,v){
            				if(v.fieldExceptEdit){
            					if(v.fieldFrontType=='t_date')laydate.render({elem:'.layui-layer #'+v.fields,type:'date',trigger:'click'});
               					if(v.fieldFrontType=='t_datetime')laydate.render({elem:'.layui-layer #'+v.fields,type:'datetime',trigger:'click'});
            				}
            			})
            			form.render();
            		},
            		yes: function(index, layero){
            			var pd=[];
						pd[0]={};
						pd[0]["nid"]=nid;
            			$.each(k_fields,function(i,v){
            				if(v.fieldExceptEdit){
            					if(v.fieldMatched && v.fieldFrontType=='t_dropdown')pd[0][v.fieldMatched]=layero.find('#'+v.fields).val();
            					else pd[0][v.fields]=layero.find('#'+v.fields).val();
            				}
            			})
	        			pd = {'infoItems':JSON.stringify(pd)};//转化为json字符串格式
	        		    $.operate.post(moduleUrl+'/xgxxpost', pd, function(res){
	        		        if(res.code == 0){
	        		        	goUrl(moduleUrl+'/edit?nid='+nid);
	        		        }
	        		    });
            		}
            	});
   			break;
	    };
	});
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染
	moneyCalculation();//表格编辑——资金计算
	/* 发货方式联动发货物流 */
	form.on('select()', function(data){
		if(data.elem.id == 'vFhFsName'){
			$("#vFhWl").val('');
			$("#vFhWlName").empty();
			$.ajax({
				url: '/base/baseinfo/list?vtype=fhwl&pguidName='+$("#vFhFsName").find("option:selected").text(),
				type: 'get',
				dataType: 'json',
				success: function(result) {
					$('#vFhWlName').append(new Option('',''));
					$.each(result.data,function(i,v){
						$('#vFhWlName').append(new Option(v.vname,v.vid));
					});
					form.render();
				}
			});
		}
	});
})
</script>
</body>
</html>